import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { brandList } from '#/api/trade/brand';


export const querySchema: FormSchemaGetter = () => [
  {
    component: 'ApiSelect',
    componentProps: {
      api: () => brandList(),
      resultField: 'rows',
      labelField: 'brandName',
      valueField: 'id',
      showSearch: true,
      filterOption: (input: string, option: any) => {
        return option.label.toLowerCase().includes(input.toLowerCase());
      },
    },
    fieldName: 'brandId',
    label: '品牌',
  },
  {
    component: 'Input',
    fieldName: 'spuCode',
    label: 'SPU编码',
  },
  {
    component: 'Input',
    fieldName: 'spuName',
    label: 'SPU名称',
  },
  
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: 'SPU编码',
    field: 'spuCode',
  },
  {
    title: 'SPU名称',
    field: 'spuName',
  },
  {
    title: '品牌',
    field: 'brandName',
  },
  {
    title: '编辑人',
    field: 'updateByUserName',
  },
  {
    title: '编辑时间',
    field: 'updateTime',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: 'SPU ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: 'SPU编码',
    fieldName: 'spuCode',
    component: 'Input',
    componentProps: {
      placeholder: '请输入SPU编码，忽略则自动生成',
    },
    // rules: 'required', // 改为非必填，提交时自动生成
  },
  {
    label: 'SPU名称',
    fieldName: 'spuName',
    component: 'Input',
    rules: 'required',
  },
  {
    component: 'ApiSelect',
    componentProps: {
      api: () => brandList(),
      resultField: 'rows',
      labelField: 'brandName',
      valueField: 'id',
      showSearch: true,
      filterOption: (input: string, option: any) => {
        return option.label.toLowerCase().includes(input.toLowerCase());
      },
    },
    label: '品牌',
    fieldName: 'brandId',
    rules: 'selectRequired',
  },
  
];
